package cn.jetpiece.cloud.resource.app.modular.scan.controller;

import cn.jetpiece.cloud.resource.annotation.keys.ResourceKey;
import cn.jetpiece.cloud.resource.annotation.model.RegisterApiDocParam;
import cn.jetpiece.cloud.resource.annotation.model.RegisterResourceParam;
import cn.jetpiece.cloud.resource.app.modular.scan.service.ResourceService;
import cn.jetpiece.cloud.resource.modular.api.RegisterResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 资源表控制器
 *
 * @author XuJZ
 * @since 2020-01-09 09:15:44
 */
@RestController
public class RegisterResourceController implements RegisterResourceService {

    @Autowired
    private ResourceService resourceService;
    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public void registerResource(@RequestBody RegisterResourceParam param) {
        resourceService.registerResource(param);
    }

    @Override
    public void registerApiDoc(@RequestBody RegisterApiDocParam param) {
        redisTemplate.boundHashOps(ResourceKey.API_DOC).put(param.getName(), param.getSwaggerResources());
    }

}
